package com.banshuibao.bsb_android.adapter;

import android.content.Context;
import android.graphics.Color;
import android.text.Spannable;
import android.text.SpannableStringBuilder;
import android.text.TextUtils;
import android.text.style.ForegroundColorSpan;
import android.widget.TextView;

import com.banshuibao.bsb_android.R;
import com.banshuibao.bsb_android.model.ConsutationModel;
import com.banshuibao.bsb_android.model.UnAnswerModel;
import com.banshuibao.bsb_android.util.TimeUtil;

import java.util.List;

/**
 * Created by Administrator on 2017/12/22.
 */

public class UnAnswerAdapter extends MineBaseAdapter<UnAnswerModel.DataBean> {

    private Context context;

    public UnAnswerAdapter(Context context, List<UnAnswerModel.DataBean> data, int layoutResId) {
        super(context, data, layoutResId);
        this.context = context;
    }

    @Override
    protected void bindData(ViewHolder holder, UnAnswerModel.DataBean item) {
        TextView content = (TextView) holder.getView(R.id.content);
        TextView date = (TextView) holder.getView(R.id.date);
        TextView status = (TextView) holder.getView(R.id.status);

        content.setText("问:  " + item.getContent());
        SpannableStringBuilder builder = new SpannableStringBuilder(content.getText().toString());
        ForegroundColorSpan yellowSpan = new ForegroundColorSpan(context.getResources().getColor(R.color.answer_status));
        builder.setSpan(yellowSpan, 0,2, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        content.setText(builder);
        String time = null;
        if (item.getCreateDate() != 0) {
            time = TimeUtil.format(item.getCreateDate());
        } else {
            time = "";
        }
        date.setText(time);
        //问题状态
        String itemStatus = item.getStatus();
        if (!TextUtils.isEmpty(itemStatus)) {
            if (itemStatus.equals("0")) {
                status.setText("未回答");
                status.setTextColor(context.getResources().getColor(R.color.answer_status));
            } else if (itemStatus.equals("1")) {
                status.setText("已回答");
                status.setTextColor(context.getResources().getColor(R.color.status_color));
            }
        }
    }
}
